define(function () {
    'use strict';

    function ctrl($scope,$state,$stateParams,$ionicPopup,LocalCacheService,WebService) {

        var par = $scope.param = {};

        $scope.$on('$ionicView.beforeEnter', function() {
            $scope.user = LocalCacheService.getOpenUser();
            par.open_status = $stateParams["open_status"];
            if(par.open_status == 1) {
                init($scope.user.client_id);
            }

            WebService.wtAd("xcm_open_result").then(function(data){
                par.ads = data;
            });
        });

        function init(client_id){
            WebService.openActChannelInfo(client_id).then(
                function(data){
                    //有活动
                    if(data && data.paper_id) {
                        $ionicPopup.confirm({
                            cssClass: "kDialog",
                            template: "您已完成开户，现小财迷正在举办“体验赢大奖”活动，体验即有机会赢取1000元现金红包，诚邀您的参与！",
                            okText:"立即参加",
                            cancelText:"不参加"
                        }).then(function(res) {
                            if(res) {
                                WebService.channelStep("date").then(function(data){
                                    if(data && data.length > 0) {
                                        var url = data[0].imgUrl.split("/")[1];
                                        var id = data[0].imgUrl.split("/")[2];
                                        $state.go(url, {id : id});
                                    }
                                })
                            }
                        });
                    }
                }
            );
        }
    }

    ctrl.$inject = ['$scope','$state','$stateParams','$ionicPopup','LocalCacheService','WebService'];
    return ctrl;
});